package com.vehicle.coupon.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vehicle.common.log.annotation.Log;
import com.vehicle.common.log.enums.BusinessType;
import com.vehicle.common.security.annotation.PreAuthorize;
import com.vehicle.coupon.domain.CouponRecord;
import com.vehicle.coupon.service.ICouponRecordService;
import com.vehicle.common.core.web.controller.BaseController;
import com.vehicle.common.core.web.domain.AjaxResult;
import com.vehicle.common.core.utils.poi.ExcelUtil;
import com.vehicle.common.core.web.page.TableDataInfo;

/**
 * 优惠券领取记录Controller
 *
 * @author XU
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/couponRecord")
public class CouponRecordController extends BaseController
{
    @Autowired
    private ICouponRecordService couponRecordService;

    /**
     * 查询优惠券领取记录列表
     */
    @PreAuthorize(hasPermi = "coupon:couponRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(CouponRecord couponRecord)
    {
        startPage();
        List<CouponRecord> list = couponRecordService.selectCouponRecordList(couponRecord);
        return getDataTable(list);
    }

    /**
     * 导出优惠券领取记录列表
     */
    @PreAuthorize(hasPermi = "coupon:couponRecord:export")
    @Log(title = "优惠券领取记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponRecord couponRecord) throws IOException
    {
        List<CouponRecord> list = couponRecordService.selectCouponRecordList(couponRecord);
        ExcelUtil<CouponRecord> util = new ExcelUtil<CouponRecord>(CouponRecord.class);
        util.exportExcel(response, list, "优惠券领取记录数据");
    }

    /**
     * 获取优惠券领取记录详细信息
     */
    @PreAuthorize(hasPermi = "coupon:couponRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(couponRecordService.selectCouponRecordById(id));
    }

    /**
     * 新增优惠券领取记录
     */
    @PreAuthorize(hasPermi = "coupon:couponRecord:add")
    @Log(title = "优惠券领取记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponRecord couponRecord)
    {
        return toAjax(couponRecordService.insertCouponRecord(couponRecord));
    }

    /**
     * 修改优惠券领取记录
     */
    @PreAuthorize(hasPermi = "coupon:couponRecord:edit")
    @Log(title = "优惠券领取记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponRecord couponRecord)
    {
        return toAjax(couponRecordService.updateCouponRecord(couponRecord));
    }

    /**
     * 删除优惠券领取记录
     */
    @PreAuthorize(hasPermi = "coupon:couponRecord:remove")
    @Log(title = "优惠券领取记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(couponRecordService.deleteCouponRecordByIds(ids));
    }
}
